package com.demohomework.homeworkdemo.service.impl;

import com.demohomework.homeworkdemo.mapper.ClassMapper;
import com.demohomework.homeworkdemo.pojo.Class;
import com.demohomework.homeworkdemo.service.ClassService;
import com.demohomework.homeworkdemo.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ClassServiceImpl implements ClassService {
    @Autowired
    private ClassMapper classMapper;

    @Override
    public void add(Class cls) {
        classMapper.add(cls);
    }

    @Override
    public List<Class> list() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        return classMapper.list(id);
    }

    @Override
    public Class findId(Integer id) {
        return classMapper.findId(id);
    }

    @Override
    public void update(Class cls) {
        classMapper.update(cls);
    }

    @Override
    public void delete(Class cls) {
         classMapper.delete(cls);
    }

    @Override
    public List<Class> findByStudentId(Integer stuId) {
        return classMapper.findByStudentId(stuId);
    }

    @Override
    public List<Class> findByCourseId(Integer courseId) {
        return classMapper.findByCourseId(courseId);
    }

    @Override
    public void deleteByStudentIdAndCourseId(Integer stuId, Integer couId) {
        classMapper.deleteByStudentIdAndCourseId(stuId, couId);
    }
}
